<template>
  <div class="details">

    <!--滚动图-->
    <div class="swiper">
      <swiper :options="swiperOption">
        <swiper-slide v-for="pic in detail.detailPic" :key="pic.id">
          <img :src="pic" alt="">
        </swiper-slide>
        <div class="swiper-pagination" slot="pagination"></div>
      </swiper>
    </div>


    <div class="m-detailBaseInfo">
      <!--商品介绍 传递数据给Info(child)-->
      <!--<goods-info :info="detail"></goods-info>-->
      <goods-info></goods-info>

      <!--服务-->
      <goods-service></goods-service>

      <!--评价 传递数据给comment(child)-->
      <goods-comment :comment="detail.comment"></goods-comment>
    </div>

    <!--商品参数-->
    <goods-attr :attr="detail.attr"></goods-attr>

    <!--图片描述(这里应该是富文本描述)-->
    <div class="dt-section dt-section-1">
      <div class="m-detailHtml">
        <p v-for="item in detail.detailHtml">
          <img :src="item">
        </p>
      </div>
    </div>

    <go-top></go-top>

  </div>
</template>

<script>
  import {Indicator} from 'mint-ui'
  import goodsComment from './goodsComment'
  import goodsAttr from './goodsAttr'
  import goodsService from './goodsService'
  import goodsInfo from './goodsInfo'
  import goTop from '@/components/public/GoTop'

  export default {

    name: 'Detail',

    data () {
      return {
        swiperOption: {
          autoplay: 3500,
          loop: true,
          setWrapperSize: true,
          pagination: '.swiper-pagination',
          paginationType: 'fraction',
          paginationClickable: true,
          mousewheelControl: true,
          observeParents: true
        }
      }
    },
    components: {
      goodsComment,
      goodsAttr,
      goodsService,
      goodsInfo,
      goTop
    },

    created () {
      Indicator.open('加载中...')
      console.log('加载中...')
      let type = this.$route.path.split('/')[2]
      let id = this.$route.path.split('/')[4]

      console.log('goodsDetails ', {type, id})
      /** 后台获取商品详情 */
      this.$store.dispatch('getDetail', {type, id})
    },
    mounted () {
      console.log('goodsDetails mountd:  ', this.$route.path)
    },
    computed: {
      /**
       * Computed properties to be mixed into the Vue instance.
       * All getters and setters have their this context automatically bound to the Vue instance.
       *
       * The computed property "detail" is already defined in fetchApi.
       */
      detail () {
        console.log(' ---goodsDetails  computed ---')
        Indicator.close()
        /**
         * Vuex uses a single state tree - that is,
         * this single object contains all your application level state and serves as the
         * "single source of truth". This also means usually you will have only one store for
         *  each application.
         */
//        console.log(this.$store.getters.Detail)
        return this.$store.getters.Detail
      }
    }
  }
</script>

<style scoped>
  .details {
    margin-bottom: 1.38667rem;
    background-color: #fff;
  }

  .swiper {
    position: relative;
    position: 1;
  }

  .swiper-pagination.swiper-pagination-fraction {
    position: absolute;
    left: auto;
    right: .4rem;
    width: .72rem;
    height: .37333rem;
    line-height: .37333rem;
    border: 1px solid rgba(0, 0, 0, .15);
    font-size: .26667rem;
    text-align: center;
    color: #333;
    background-color: #fff;
    transition: 0s;
    border-radius: 4px;
  }

  /*pics*/
  .dt-section-1, .dt-section-2 {
    border-bottom: none;
    background-color: #fff;
    width: 100%;
  }

  .m-detailHtml {
    width: 100%;
  }

  .m-detailHtml * {
    margin: 0;
    padding: 0;
    line-height: 0;
  }

  /**/


</style>
